<template>
  <div class="vip-side-bar" :class="{ 'is-collapse': collapse }">
    <!--    <vip-logo v-if="layout === 'comprehensive' || layout === 'vertical'" class="fixed-logo" />-->

    <el-scrollbar>
      <el-menu
        :collapse="collapse"
        :collapse-transition="false"
        :default-active="activeMenu.data"
        :unique-opened="uniqueOpened"
        menu-trigger="click"
        background-color="var(--el-menu-background-color)"
        text-color="var(--el-menu-color-text)"
        mode="vertical"
      >
        <VipMenu v-for="(item, index) in handleRoutes" :key="index + item.name" :item="item" />
      </el-menu>
    </el-scrollbar>

    <VipMenuFloatFold />
  </div>
</template>

<script lang="ts" setup>
import { uniqueOpened } from '/@lib/config'
import { useRoutesStore } from '/@/store/modules/routes'
import { useSettingsStore } from '/@/store/modules/settings'

defineOptions({
  name: 'VipSideBar'
})

const props = defineProps({
  layout: {
    type: String,
    default: 'vertical'
  }
})

const settingsStore = useSettingsStore()
const { collapse } = storeToRefs(settingsStore)
const routesStore = useRoutesStore()
const { getRoutes: routes, getActiveMenu: activeMenu, getPartialRoutes: partialRoutes } = storeToRefs(routesStore)

const handleRoutes = computed(() => {
  return props.layout === 'comprehensive'
    ? partialRoutes.value
    : routes.value.flatMap((route: any) => (route.meta.levelHidden && route.children ? [...route.children] : route))
})
</script>

<style lang="scss" scoped>
@mixin active {
  &:hover {
    color: var(--el-color-white);
    background-color: var(--el-color-primary);
    //padding: 5px 10px 5px 10px;
  }

  &.is-active {
    color: var(--el-color-white);
    background-color: var(--el-color-primary);
    //padding: 5px 10px 5px 10px;
  }
}

.vip-side-bar {
  position: relative;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  //width: var(--el-left-menu-width);
  height: 100vh;
  width: calc(var(--el-left-menu-width) - 50px);
  background: var(--el-menu-background-color);
  border-right: 1px solid var(--el-border-color);
  //box-shadow: 2px 0 8px 0 rgba(29, 35, 41, 0.05);
  transition: var(--el-transition);
  padding-top: 5px;

  :deep() {
    .menu-float-fold {
      //left: var(--el-left-menu-width) !important;
      left: calc(var(--el-left-menu-width) - 50px) !important;
    }
  }

  &.is-collapse {
    //z-index: calc(var(--el-z-index) + 1);
    width: var(--el-left-menu-width-min);
    //border-right: 0;
    border-right: 1px solid var(--el-border-color);

    :deep() {
      .menu-float-fold {
        left: calc(var(--el-left-menu-width-min)) !important;
      }

      .el-menu {
        > .el-menu-item,
        > .el-sub-menu .el-sub-menu__title {
          justify-content: center;
          height: var(--el-menu-item-height);
          line-height: var(--el-menu-item-height);
          //height: calc(var(--el-menu-item-height) - 6px);
          //line-height: calc(var(--el-menu-item-height) - 6px);
          text-align: center;
          padding: 0;

          [class*='ri'] {
            display: block;
            padding: 0 !important;
            margin: 0 !important;
          }

          .el-tag {
            display: none;
          }
        }
      }

      .el-menu-item,
      .el-sub-menu {
        text-align: left;
      }

      .el-menu--collapse {
        border-right: 0;

        .el-sub-menu__icon-arrow {
          right: 10px;
          margin-top: -3px;
        }
      }
    }
  }

  :deep() {
    //.el-menu.el-menu--vertical {
    //  margin-top: var(--el-header-height);
    //}
    .el-menu {
      border: 0 !important;
    }

    .el-scrollbar__wrap {
      overflow-x: hidden;
    }

    .el-menu-item,
    .el-sub-menu__title {
      margin: 0 10px 5px 10px;
      //margin: 5px 10px 5px 10px;
      //padding: 5px 10px 5px 10px;
      overflow: hidden;
      height: var(--el-menu-item-height) !important;
      line-height: var(--el-menu-item-height) !important;
      border-radius: var(--el-border-radius-base);
      text-overflow: ellipsis;
      white-space: nowrap;
      text-align: center !important;
      @include active;

      * {
        vertical-align: middle !important;
      }
    }
  }
}
</style>

<style lang="scss">
//.el-menu {
//  border-right: 0;
//}
//
//.el-menu--popup-right-start {
//  --el-menu-hover-bg-color: var(--el-color-primary) !important;
//  --el-menu-active-color: var(--el-color-white) !important;
//
//  .is-active {
//    background: var(--el-color-primary) !important;
//  }
//}
</style>
